import {IMock} from './i-mock';
import {MockConfigItem} from '../../entity/mock-config-item';
import {MockUtils} from '../mock-utils';
import {AlertMessage} from '../../entity/alert-message';
import {deepCopy} from '../entity-utils';

export class MapMock implements IMock {
    /**
     * 新增的map key
     */
    mapKey: string;

    getBaseTypeMockConfigDisplay(mockConfigItem: MockConfigItem): string {
        return '';
    }

    onSave(mockConfigItem: MockConfigItem): boolean {
        if (!this.mapKey || this.mapKey.length === 0) {
            MockUtils.setMockInfo(AlertMessage.error('Map key不能为空！'));
            return false;
        }

        const newItem = deepCopy(mockConfigItem.mapValueConfig);
        newItem.key = this.mapKey;
        mockConfigItem.children.push(newItem);
        return true;
    }

}
